#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=2000,MOD=64123;
int n,k,w,a[MAXN],head[MAXN],cnt,f[MAXN][MAXN],ans;
bool val[MAXN];
struct edge
{
	int v,next;
}e[MAXN*2];
void addedge(int x,int y)
{
	e[++cnt]=(edge){y,head[x]};
	head[x]=cnt;
	return;
}
void dfs(int u,int lst)
{
	if(val[u])
	{
		for(int j=k;j;--j)f[u][j]=f[u][j-1];
		f[u][0]=0;
	}
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].v;
		if(v==lst)continue;
		memcpy(f[v],f[u],sizeof(f[u]));
		dfs(v,u);
		for(int j=0;j<=k;++j)(f[u][j]+=f[v][j])%=MOD;
	}
}
int main()
{
	n=read();k=read();w=read();
	for(int i=1;i<=n;++i)a[i]=read();
	for(int i=1;i<n;++i)
	{
		int x=read(),y=read();
		addedge(x,y);
		addedge(y,x);
	}
	for(int i=1;i<=n;++i)
	{
		int t=0;
		for(int j=1;j<=n;++j)
		{
			if(a[j]>a[i]||(a[j]==a[i]&&j>=i))val[j]=true,++t;
			else val[j]=false;
		}
		if(t<k)continue;
		for(int j=1;j<=k;++j)f[i][j]=0;
		f[i][0]=1;
		dfs(i,0);
		(ans+=f[i][k]*a[i]%MOD)%=MOD;
	}
	printf("%d\n",ans);
	return 0;
}
